import java.util.ArrayList;

/**
 * Created by JiaJia on 2019/5/23 0023.
 * 和为S的连续正数序列
 */
public class Code41 {
        public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {
            ArrayList<ArrayList<Integer>> arrayList=new ArrayList<>();
            ArrayList<Integer> list=new ArrayList<>();
            if (sum<3){
                return arrayList;
            }
            int small=1;
            int big=2;
            while (small<(sum+1)/2){
                int res=0;
                for (int i = small; i <=big; i++) {
                    res+=i;
                }
                if (res==sum){
                    for (int i = small; i <=big; i++) {
                        list.add(i);
                    }
                    arrayList.add(new ArrayList<Integer>(list));
                    list.clear();
                    small++;
                }else if (res>sum){
                    small++;
                }else {
                    big++;
                }
            }
            return arrayList;

        }
    }
